<?php
require_once FOREGROUND_COMMON_ACTION_SERVICE_DIR . '/ajax.php';

class foreground_order_check_action_service extends foreground_ajax_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {	     		     
	    $result = array('status' => 1, 'message' => '', 'data' => array());    
    
        $action_data = wwy_action::$data;
	    $session_member_info = $action_data['session_member_info'];
	    $member_id = $session_member_info['id'];
      
        $model_foreground_cart = wwy_resource_container::get_model_foreground_cart();
        //var_dump($model_foreground_cart); exit();
        
        $check_cart_list_good_spec_result = $model_foreground_cart->check_cart_list_good_spec($member_id);
        if($check_cart_list_good_spec_result['status'] < 0){
            //检查是否存在已下架的商品规格，若存在，则提示【您的购物车存在已下架的商品规格，将重新加载页面，清除已下架的商品规格】，然后重新加载页面，清除已下架的商品规格
            $result['status']  = -404;
            $result['message'] = '您的购物车存在已下架的商品规格，将重新加载页面，清除已下架的商品规格';
        }else{                            
            $cart_list_info = $model_foreground_cart->get_cart_list_info($member_id);
            //var_dump($cart_list_info); exit();
            if(empty($cart_list_info['cart_list'])){
                $result['status']  = -4;
                $result['message'] = '购物车没有商品，或购物车的商品规格都已下架';
            }elseif($cart_list_info['total'] < self::$data['business_config']['order_min']){
                $result['status']  = -5;
                $result['message'] = '订单请满' . self::$data['business_config']['order_min'] . '元 ^_^';
            }
        }
         
        self::set_view_status($result['status']);
        self::set_view_message($result['message']);
    }
}